Frameworks help developer to create web applications more efficiently

http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks

Keynote:

  • Flask framework for Python
  • Templates: for writing html code separately from Python code
  • Function url_for: which is used to built the URL to navigate to Flask application.
  • forms: capture data from users.
  • message flashing: notify the user each time they successfully change information in the database.

Using Flask

from flask import Flask app = Flask(__name__) @app.route('/') @app.route('/hello') def HelloWorld(): return "Hello World" if __name__ == '__main__': app.debug = True app.run(host = '0.0.0.0', port = 5000)

Running this version on localhost:5000

Routing

The route decorator is used to bind the function to a URL. - URLs with Variables: "path//path"
  • You can now visit localhost:5000/restaurants/1

Templates

  • Template is used to store HTML code separately from Python code. Using render_template()
  • You have to make a directory templates in the same directory of your code, and store your html file there.

mkdir templates

URL Building

Responding With JSON

  • API: Application Programming Interface, which allow external applications to use public information our apps want to share.
  • When an API is communicated over the Internet, following the rules of HTTP, it is called the resful API.
  • RESTful: Representational State Transfer.
  • JSON: Javascript Object Notation.

In [ ]: